package nio;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket(InetAddress.getLocalHost(), 3333);
            DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
            DataInputStream din = new DataInputStream(socket.getInputStream());
            Scanner sin = new Scanner(new BufferedInputStream(System.in));
            while (true) {
                if (sin.hasNextLine()) {
                    String mes = sin.nextLine();
                    dout.writeUTF(mes);
                    dout.flush();
                }
                if (din.available() != 0) {
                    System.out.println("client receive:" + din.readUTF());
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
